package com.tinckay.common.util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: Jean
 * @Desc:
 * @Date: 2018/10/29 21:30
 */

public class WrapperUtils<T> {

    public static final String USERID_FLAG_ONE = "user.id";
    public static final String USERID_FLAG_TWO = "userId";

    public static <T> QueryWrapper dataScopeWrapper(String userIdAlias) {
        Map<String, Object> params = new HashMap<String, Object>() {{
            put("1", 1);
            put(userIdAlias, null);
        }};
        QueryWrapper<T> wrapper = new QueryWrapper<T>().allEq(params, false);
        if (!ShiroUtils.isAdmin()) {
            params.put(userIdAlias, ShiroUtils.getCurrentUserId());
        }
        return wrapper;
    }

}
